# scripts/build-debug.sh
#!/bin/bash
source ./scripts/config.sh

cd $FFMPEG_SRC || exit 1
make clean

echo "🔧 配置 FFmpeg 调试版 (arm64-v8a) ..."

./configure \
  --prefix=$DEBUG_PREFIX \
  --target-os=android \
  --arch=$ARCH \
  --cpu=$CPU \
  --cc=$CC \
  --cxx=$CXX \
  --strip=$STRIP \
  --enable-cross-compile \
  --cross-prefix=$TOOLCHAIN/bin/aarch64-linux-android- \
  --pkg-config=pkg-config \

  # --- 禁用无关程序 ---
  --disable-doc \
  --disable-programs \
  --disable-ffmpeg \
  --disable-ffplay \
  --disable-ffprobe \
  --disable-symver \

  # --- 核心功能 ---
  --disable-everything \
  --enable-decoders \
  --enable-encoders \
  --enable-demuxer=h264,hevc,mpegts,mp4,aac,wav,pcm_s16le,rawvideo,mov,avi \
  --enable-muxer=h264,hevc,mpegts,mp4,aac,wav,pcm_s16le,rawvideo,mov,avi \
  --enable-parser=h264,h265,aac,mpeg4video,mpegvideo \
  --enable-protocol=file,http,https,rtmp,rtsp,rtp \
  --enable-filter=scale,resample,crop,pad,format,aformat \

  # --- 调试专用配置 ---
  --enable-debug=3 \
  --disable-optimizations \
  --disable-small \
  --disable-stripping \
  --disable-asm \
  --disable-inline-asm \
  --disable-neon \          # 避免汇编
  --disable-neon-clobber-use \

  # --- 调试标志 ---
  --extra-cflags='-g3 -O0 -fPIC -fno-omit-frame-pointer -DDEBUG' \
  --extra-ldflags='-Wl,--gc-sections' \

  # --- 许可 ---
  --enable-gpl \
  --enable-nonfree \
  --enable-version3 \

  # --- 输出类型 ---
  --disable-shared \
  --enable-static \

  || exit 1

make -j$(nproc) && make install
echo "✅ 调试版构建完成：$DEBUG_PREFIX"